package com.hhit.zhgd.enums

import cn.hutool.core.util.StrUtil

enum class WitnessOrNotEnum(val code: Int, val desc: String) {
    UNKNOWN(-1, "未知"), WITNESS_OR_NOT_YES(1, "是"), WITNESS_OR_NOT_NO(0, "否");

    override fun toString(): String {
        return "$name ($code: $desc)"
    }

    companion object {
        fun fromCode(code: Int): String {
            for (witnessOrNotEnum in values()) {
                if (witnessOrNotEnum.code == code) {
                    return witnessOrNotEnum.desc
                }
            }
            return StrUtil.EMPTY
        }

        fun fromMessage(message: String): Int {
            if (message == null || message.isBlank() || "未知" == message) {
                return -1
            }
            for (witnessOrNotEnum in values()) {
                if (witnessOrNotEnum.desc == message) {
                    return witnessOrNotEnum.code
                }
            }
            return -1
        }
    }
}